#ifndef __CO_HEARTBEAT_H__
#define __CO_HEARTBEAT_H__

#include <stdbool.h>
#include "utils/utils_timer.h"
#define INFO_CLASS           0x26
/* 周期上报数据 */
#define DAT_RPT_ID           0x01    
/* 主动查询数据，并通过INFO-DAT-RPT上报 */
#define DAT_POLL_ID          0x02


#define CFG_CLASS            0x23
/* IOT配置仪表声音 */
#define CFG_CO_AUD_ID        0x01
/* IOT配置仪表蓝牙感应距离 */
#define CO_BLE_DISTANCE      0x07   
/* IOT配置仪表蓝牙无感解锁开关 */
#define CO_BLE_LOCK          0x08   
/* IOT配置仪表音量等级 */
#define CO_VOLUME_ID         0x32  

#define IOT_CLASS            0x32
/* 请求仪表重启 */
#define CO_RESET_ID          0x01
/* 请求仪表关机 */
#define CO_OFF_ID       0x02
/* 请求仪表更新车端数据 */
#define CO_UPD_ID            0x03
/* 请求仪表播放指定音频，IOT当事件发生时触发即可，不需要关注参数配置和播放时长、次数等 */
#define IOT_CO_AUDIO_ID          0x04

#define ACK_CLASS            0x01
/* 消息应答 */
#define ACK_ID               0x00

#define SEQNUM_LEN          32


#include "global.h"
#define hb_malloc(x)		qlmalloc(x)
#define	hb_free(x)		    qlfree(x)

#define SYNC1_SIZE          1
#define SYNC2_SIZE          1
#define CLASS_SIZE          1
#define ID_SIZE             1
#define PAYLOAD_LEN_SIZE    2
#define CRC16_SIZE          2
#define HB_HEADER_SIZE      SYNC1_SIZE + SYNC2_SIZE + CLASS_SIZE + ID_SIZE + PAYLOAD_LEN_SIZE
#define HB_FIX_SIZE         SYNC1_SIZE + SYNC2_SIZE + CLASS_SIZE + ID_SIZE + PAYLOAD_LEN_SIZE + CRC16_SIZE
#define OFFSET_PAYLOAD_LENL SYNC1_SIZE + SYNC2_SIZE + CLASS_SIZE + ID_SIZE + 1
#define OFFSET_PAYLOAD_LENH SYNC1_SIZE + SYNC2_SIZE + CLASS_SIZE + ID_SIZE + 2
/* 电芯数 */
#define BATT_CELL_NUM       1

/* 上电后前十秒会高频发送，单位：ms */
#define HIGH_FREQ_DURATION  10000
/* 上电后前十秒的周期发送间隔，单位：ms */
#define SEND_INTERVAL_PON   500
/* 周期发送间隔，单位：ms */
#define SEND_INTERVAL       10000
/* 心跳包500ms一个，连续丢失6次心跳包则判断CO MCU已关机 */
#define CO_MCU_HB_POWEROFF_INTERVAL         3    //sec
/* 仪表发送周期, uint:ms */
#define CO_MCU_HB_INTERVAL          500

/* 功能号 */
#define FUNC_VERSION        0x04
#define FUNC_SEQNUM         0x05
#define FUNC_CUST_SN        0x06

/* 节点号 */
#define NODE_EMU            0x3100
#define NODE_CO             0x3200
#define NODE_BATT           0x3300
#define NODE_BLE            0x3400
#define NODE_ELOCK          0x3600
#define NODE_LBATT          0x5100
#define NODE_IOT            0x5200
#define NODE_BACKUP_BATT    0x5300

/* 软硬件版本号 */
#define EMU_VERSION         NODE_EMU+FUNC_VERSION
#define CO_VERSION          NODE_CO+FUNC_VERSION
#define BATT_VERSION        NODE_BATT+FUNC_VERSION
#define BLE_VERSION         NODE_BLE+FUNC_VERSION
#define VR_LEN              3

/* 序列号 */
#define BATT_SEQNUM         NODE_BATT+FUNC_SEQNUM
#define BACKUP_BATT_SEQNUM  0x5306
#define EMU_SEQNUM          NODE_EMU+FUNC_SEQNUM
#define CO_SEQNUM           NODE_CO+FUNC_SEQNUM 
#define CO_CUST_SN          NODE_CO+FUNC_CUST_SN
#ifndef SEQNUM_LEN
#error "SEQNUM_LEN is not defined"
#endif          

/* 电机控制器信息1 */
#define EMU_INFO1                           NODE_EMU+0x00
#define EMU_INFO1_LEN                       8

/* 电机控制器信息2 */
#define EMU_INFO2                           NODE_EMU+0x01
#define EMU_INFO2_LEN                       8

/* 车端系统参数 */
#define BIKE_SYSTEM_INFO                     NODE_EMU+0x03
#define BIKE_SYSTEM_INFO_LEN                 8

/* 电机控制器状态信息1 */
#define EMU_STAT_INFO1                      NODE_EMU+0x0A
#define EMU_STAT_INFO1_LEN                  8

/* 电机控制器状态信息2 */
#define EMU_STAT_INFO2                      NODE_EMU+0x0B
#define EMU_STAT_INFO2_LEN                  8

/* 电机控制器状态信息3 */
#define EMU_STAT_INFO3                      NODE_EMU+0x0C
#define EMU_STAT_INFO3_LEN                  8

/* 软件 eeprom 版本号 */
#define EMU_EPPR_VR                         NODE_EMU+0x0D
#define EMU_EPPR_VR_LEN                     8

/* 电池容量信息 */
#define BATT_CAPACITY_INFO                  NODE_BATT+0x00
#define BACKUP_BATT_CAPACITY_INFO           NODE_BACKUP_BATT+0x00
#define BATT_CAPACITY_INFO_LEN              8

/* 电池运行状态信息 */
#define BATT_RUN_STATUS_INFO                NODE_BATT+0x01
#define BACKUP_BATT_RUN_STATUS_INFO         NODE_BACKUP_BATT+0x01
#define BATT_RUN_STATUS_INFO_LEN            8

/* 电池充电状态信息 */
#define BATT_CHARGE_STATUS_INFO             NODE_BATT+0x02
#define BACKUP_BATT_CHARGE_STATUS_INFO      NODE_BACKUP_BATT+0x02
#define BATT_CHARGE_STATUS_INFO_LEN         8

/* 电池电芯电压 */
#define BATT_CELL_VOLT_INFO                 NODE_BATT+0x0A
#define BACKUP_BATT_CELL_VOLT_INFO          NODE_BACKUP_BATT+0x0A
/* !!! 注意：电芯数量待定 */
#define BATT_CELL_VOLT_INFO_LEN             2 * BATT_CELL_NUM

/* 电池状态信息 */
#define BATT_STATUS_INFO                    NODE_BATT+0x0E
#define BACKUP_BATT_STATUS_INFO             NODE_BACKUP_BATT+0x0E
#define BATT_STATUS_INFO_LEN                8

/* 小电池（锂电池）状态 */
#define LBATT_STATUS_INFO                   NODE_LBATT+0x01
#define LBATT_STATUS_INFO_LEN               3

/* 外电状态实时信息 */
#define EXBAT_STATUS_INFO                   0x5102
#define EXBAT_STATUS_INFO_LEN               8

/* 充电器交互状态 */
#define CHARGER_INFO                        0x3500
#define CHARGER_INFO_LEN                    8

/* 电子锁状态信息 */
#define ELOCK_INFO                          NODE_ELOCK+0x02
#define ELOCK_INFO_LEN                      1

/* 仪表系统参数 */
#define CO_INFO                             NODE_CO+0x01
#define CO_INFO_LEN                         8

/* 电控故障码 */
#define ECON_FAULT_INFO                     NODE_CO+0xB2
/* 电池故障码 */
#define BATT_FAULT_INFO                     NODE_CO+0xB5
/* 备用电池故障码 */
#define BACKUP_BATT_FAULT_INFO              NODE_CO+0xB6
/* 充电器故障码 */
#define CHARGER_FAULT_INFO                  NODE_CO+0xB7
/* 电子锁故障码 */
#define ELOCK_FAULT_INFO                    NODE_CO+0xB8

/* 可忽略故障码长度的定义 */
#define FAULT_INFO_LEN   8
#ifndef FAULT_INFO_LEN
#error "CO_FAULT_INFO_LEN is not defined"
#endif

/* 仪表密码鉴权 */
#define CO_PWD_AUTH                         NODE_CO+0xA2
#define CO_PWD_AUTH_LEN                     1   

/* 小电池充电状态 */
#define LBATT_CHG_STAT                      0x32A3
#define LBATT_CHG_STAT_LEN                  6

/* 蓝牙MAC */
#define BLE_MAC                             NODE_BLE+0x01
#define BLE_MAC_LEN                         6

/* 蓝牙状态 */
#define BLE_STATUS                          NODE_BLE+0x02
#define BLE_STATUS_LEN                      1

/* IoT固件版本信息 */
#define IOT_FW_VERSION                      NODE_IOT+0x00
#define IOT_FW_VERSION_LEN                  125

/* IoT网络状态信息 */
#define IOT_NET_STATUS                      NODE_IOT+0x01
#define IOT_NET_STATUS_LEN                  4

/* IoTGNSS状态信息 */
#define IOT_GNSS_STATUS_INFO                NODE_IOT+0x02
#define IOT_GNSS_STATUS_INFO_LEN            7

/* IoT状态信息 */
#define IOT_STATUS_INFO                     NODE_IOT+0x03
#define IOT_STATUS_INFO_LEN                 2

/* IoTSim卡信息 */
#define IOT_SIM_INFO                        NODE_IOT+0x04
# define IOT_SIM_INFO_LEN                   37

/* IoT告警状态 */
#define IOT_ALARM_INFO                      NODE_IOT+0x05
#define IOT_ALARM_INFO_LEN                  7

/* IoT->仪表指令配置 */
#define IOT_INSTRUCT_CONF                   NODE_IOT+0xA2
#define IOT_INSTRUCT_CONF_LEN               2

/* IoT->仪表参数配置 */
#define IOT_PARAM_CONF                      NODE_IOT+0xA3
#define IOT_PARAM_CONF_LEN                  2

/* IoT->仪表声音配置 */
#define IOT_SOUND_CONF                      NODE_IOT+0xA4
#define IOT_SOUND_CONF_LEN                  18

/* IoT->仪表时间信息 */
#define IOT_DATE_INFO                       NODE_IOT+0x10
#define IOT_DATE_INFO_LEN                   7

#define MDM_VER_LEN                         40
#define IMEI_LEN                            16 
#define IOT_VER_LEN                         3
#define IOT_SN_LEN                          32
#define GPS_VER_LEN                         32
#define IOT_HW_LEN                          2

#define GNSS_VER_LEN                        15

#define GNSS_CN_LEN                         5

#define IOT_HW_LEN                          2

#define ICCID_LEN                           21
#define IMSI_LEN                            16

#define IMSI_LEN                            16

/* 仪表音频参数配置长度 */
#define CFG_CO_AUD_LEN                      18

/* 音量等级配置长度 */
#define CFG_CO_VOLUME_LEN                   1

/* 配置仪表蓝牙参数长度 */
#define CFG_CO_BLE_LEN                      2

#define IOT_CO_AUDIO_LEN                    1

#define FAULT_CODE_LEN                      32

#define comm_malloc(x) pvPortMalloc(x)
#define comm_free(x)   vPortFree(x)

enum co_result {
    ACK = 0,
    NACK = 1,
};

enum co_type {
    SYNC1 = 0,
    SYNC2,
    ID,
    LENL,
    LENH,
    PAYLOAD,
    CRC16,
    PARSE,
};

enum aud_type {
    AUD_TYPE_FIND_BIKE = 2,
    AUD_TYPE_ALARM,
    AUD_TYPE_BINDING = 11,
    AUD_TYPE_ENCLOSURE_IN = 14,
    AUD_TYPE_ENCLOSURE_OUT = 15,
};

typedef enum {
    FAULT_BATT,
    FAULT_BACKUP_BATT,
    FAULT_ECON,
    // FAULT_CHARGER,
    // FAULT_ELOCK,
     FAULT_NUM,
}fault_type;

/* 软硬件版本号 */
typedef __packed struct
{
    char soft_version[32];
    char hw_version[32];  
}version_t;


typedef __packed struct
{
    bool soc_is_valid;
    uint8_t soc;                    /* SOC */
    bool pwr_lvl_is_valid;
    uint8_t pwr_lvl;                /* 助力档位 */
    bool engery_consumption_is_valid;
    uint16_t engery_consumption;  /* 力矩系统能量消耗 */
    bool remain_range_is_valid;
    float remain_range;        /* 剩余里程 */
    bool single_range_is_valid;
    float single_range;        /* 单次里程 */
}electric_vehicle_info2_t;

typedef __packed struct
{
    bool is_circumference_valid;
    float wheel_circumference;    /* 车轮周长 */
    bool is_wheel_diameter_valid;                
    float wheel_diameter;         /* 轮径 */     
    bool is_speed_limit_valid; 
    float speed_limit;            /* 当前限速 */
    uint8_t cfg_pwroff;                /* 开关机设置 */  
}bike_system_info_t;


typedef __packed struct
{
    uint8_t braking_stat;           /* 断电刹状态 */                
    uint8_t motor_stat;           /* 电机状态 */      
    uint16_t motor_speed;       /* 电机转速 */
    uint16_t volt_output;         /* 力矩输出电压值 */ 
    uint16_t ride_freq;           /* 踏频 */ 
}econ_info1_t;

typedef __packed struct
{
    uint8_t deserved;                   /* 保留域 */                
    uint16_t single_rided_time;       /* 单次骑行时间 */      
    float throttle_volt;              /* 转把电压 */
    float bus_cur;                 /* 母线电流 */ 
    float bus_volt;                /* 母线电压 */ 
}econ_info2_t;

typedef __packed struct
{
    uint8_t deserved[2];                /* 保留域 */         
    float total_range;             /* 总里程 */                
    uint8_t econ_mode;                  /* 控制器模式 */      
    uint8_t econ_work_stat;             /* 控制器工作状态 */
}econ_info3_t;

typedef __packed struct
{
    uint8_t eeprom_ver[6];              /* eeprom版本号 */         
    uint8_t deserved[2];                /* 保留域 */                
}eeprom_ver_t;

typedef __packed struct
{
    bool is_standard_volume_valid;
    float standard_volume;            /* 标称容量 单位：0.01Ah*/
    bool is_full_volume_valid;
    float full_volume;                /* 满电容量 单位：0.01Ah*/     
    bool is_remain_volume_valid;
    float remain_volume;              /* 剩余容量 单位：0.01Ah*/         
    uint8_t health;                        /* 健康度 %*/   
    bool is_volume_valid;
    uint8_t volume;                        /* 电量   %*/                          
}batt_volume_info_t;

typedef __packed struct
{
    uint8_t deserved;                   /* 保留域*/   
    bool is_chg_stat_valid;      
    uint8_t chg_stat;                   /* 放电状态*/   
    bool is_temp_valid;
    int16_t temp;                         /* 温度*/
    bool is_cur_valid;
    int16_t cur;                          /* 电流 */   
    bool is_volt_valid;
    uint16_t volt;                         /* 输出电压 */                          
}batt_stat_t;


typedef __packed struct
{
    uint8_t deserved;            /* 保留域*/         
    uint8_t activate_time[2];                /* 首次激活时间*/       
    uint8_t chg_interval[2];           /* 距离上次充电的间隔*/         
    uint8_t cycle[2];                  /* 循环次数 */   
    uint8_t chg_stat;                  /* 充电状态 */                          
}batt_chg_info_t;

typedef __packed struct
{
    uint8_t supply;                 /* 外电池供电状态，0-未供电，1-供电 */
    uint8_t switch_stat;                 /* 仪表开关机状态 */
    uint8_t deserved[7];            /* 保留域*/                                
}exbatt_stat_t;

typedef struct co_data
{
    uint16_t key;
    uint8_t  len;
    bool     send;
    void     (*update)(uint8_t *data, uint16_t len);
    uint16_t (*get)(uint8_t *p_data, uint16_t len);    
}co_data_t;


enum batt_type{
    main_batt = 0,
    backup_batt,
    BATT_TYPE_MAX,
};

typedef __packed struct batt_version 
{
    char sw_ver_str[32];
    char hw_ver_str[32];
}batt_version_t;

typedef __packed struct batt_capacity_info 
{

    bool nominal_c_valid;
    uint16_t nominal_capacity;
    bool full_c_valid;
    uint16_t full_capacity;
    bool remain_c_valid;
    uint16_t remain_capacity;
    bool is_soh_valid;
    uint8_t soh;
    bool is_soc_valid;
    uint8_t soc;  
}batt_capacity_info_t;

typedef __packed struct batt_run_status_info 
{
    uint8_t reserved;
    bool discharge_s_valid;
    uint8_t discharge_status;
    bool temp_valid;
    int16_t temperature;
    bool current_valid;
    int16_t current;
    bool batt_v_valid;
    float batt_voltage;  
}batt_run_status_info_t;
  
typedef __packed struct batt_charge_status_info 
{
    uint8_t reserved;
    bool fa_time_valid;
    uint16_t first_active_time;
    bool lc_time_valid;
    uint16_t last_charge_interval;
    bool charge_c_valid;
    uint16_t charge_cycle;
    bool charge_s_valid;
    uint8_t charge_state;  
}batt_charge_status_info_t;


typedef __packed struct batt_cell_volt_info 
{
    uint8_t cell_cnt;
    uint16_t cell_volt[24];  /* 单位：mV */
}batt_cell_volt_info_t;


typedef __packed struct batt_status_info 
{
    uint16_t reserved;
    uint16_t charge_remain_time;
    uint16_t temp_min;
    uint16_t temp_max; 
}batt_status_info_t;


typedef __packed struct lbatt_status_info 
{
    uint8_t charge_state;
    uint16_t batt_voltage;
    uint16_t soc;
}li_batt_status_info_t;

typedef __packed struct iot_ver
{
    char mdm_ver[MDM_VER_LEN];
    char imei[IMEI_LEN];
    uint8_t iot_ver[IOT_VER_LEN];
    uint8_t iot_sn[IOT_SN_LEN];
    uint8_t gps_ver[GPS_VER_LEN];
    uint8_t iot_hw[IOT_HW_LEN];
}iot_fw_t;

typedef __packed struct iot_net
{
    uint8_t sim_valid;
    uint8_t net_status;
    int8_t csq;
    uint8_t rat_state;
}iot_net_t;

typedef __packed struct iot_gnss
{
    uint8_t loc_status;
    uint8_t gnss_num;
    uint8_t gnss_cn[GNSS_CN_LEN];
}iot_gnss_t;

typedef __packed struct iot_status
{
    uint8_t plat_conn_status;
    uint8_t active_status;
}iot_status_t;

typedef __packed struct iot_sim
{
    uint8_t iccid[ICCID_LEN];
    uint8_t imsi[IMSI_LEN];
}iot_sim_t;


typedef __packed struct
{   
    /* 0: auth fail/not yet; 1: auth ok */
    uint8_t status;
}co_auth_status_t;


typedef __packed struct
{   
    /* 0: locked; 1: open; 2: locking busy; 4: openning busy */
    uint8_t status;
}co_lock_status_t;

typedef __packed struct
{   
    bool motor_temp_valid;
	float motor_temp;
	bool ctrl_temp_valid;
	float ctrl_temp;
	bool current_valid;
	float current;
	bool speed_valid;
	float speed;
}co_motor_ctrl_info_1_t;


typedef __packed struct
{   
    bool is_dipped_beam_valid; 
    /* 近光灯 */
    uint8_t dipped_beam;
    bool is_full_beam_valid;
    /* 远光灯 */
    uint8_t full_beam;
    bool is_left_turn_valid;
    /* 左转向灯 */
    uint8_t left_turn_indicator;
    bool is_right_turn_valid;
    /* 右转向灯 */
    uint8_t right_turn_indicator;
	/* 保留域 */
    uint8_t reserved;
    /* 尾灯 */
    uint8_t tail_light;
    /* 后灯 */
    uint8_t rear_light;
}co_status_info_t;


typedef __packed struct
{
    int8_t aud_switch;      /* 音效开关 */
    int8_t aud_poweron;     /* 开机音效设置 */
    int8_t aud_poweroff;    /* 关机音效设置 */
    int8_t aud_findbike;    /* 寻车声音设置 */
    int8_t aud_caralarm;    /* 震动或骑行异常报警音设置 */
    int8_t aud_bat_low;     /* 电量低音效 */
    int8_t aud_bat_err;     /* 电池故障音效 */
    int8_t aud_shift_gear;  /* 换挡提示音 */
    int8_t aud_ovr_spd;     /* 电机超速提示音 */
    int8_t aud_ble_band;    /* 蓝牙绑定成功提示音 */
    int8_t aud_charger_in;  /* 充电器连接成功提示音 */
    int8_t aud_bkbat_in;    /* 副电池接入提示音 */
    int8_t aud_fence_in;    /* 进入电子围栏提示音 */
    int8_t aud_fence_out;   /* 退出电子围栏提示音 */
    int8_t aud_date_mc;     /* 圣诞节日(MerryChristmas)提示音 */
    int8_t aud_date_tg;     /* 感恩节日(thanks giving)提示音 */
    int8_t aud_date_bd;     /* 生日(birthday)提示音 */
    int8_t aud_date_ny;     /* 新年(newyear)提示音 */
}aud_cfg_t;


typedef __packed struct
{
    uint8_t ble_detect_level;                   /* 蓝牙感应距离 */
    uint8_t ble_inductiveunlock_enable;         /* 蓝牙无感解锁开关 */
}ble_cfg_t;

typedef struct
{
    uint8_t deserved[2];
    bool is_hard_fault;
    bool is_high_temp;
    bool is_volt_err;
    bool is_close;
    bool is_comm_timeout;
    float charge_temp;
    float charge_cur;
    float charge_volt;
    utils_time_t timer;
}charger_info_t;

typedef struct
{
    uint8_t num;
    uint8_t code[FAULT_CODE_LEN]; 
}co_fault_code_t;

typedef __packed struct
{
    uint16_t total_chg_cnt;
    uint32_t total_chg_time;
}lbatt_chg_stat_t;

extern co_motor_ctrl_info_1_t co_motor_ctrl_info_1;
extern co_lock_status_t co_lock_status;
extern co_auth_status_t co_auth_status;
//extern co_status_info_t co_status_info;

/**
 * @brief 电池版本获取
 * 
 * @param p_data 
 * @param len 
 * @return uint16_t 
 */
uint16_t batt_version_get(uint8_t *p_data, uint16_t len);

/**
 * @brief 电池序列号获取
 * 
 * @param p_data 
 * @param len 
 * @return uint16_t 
 */
uint16_t batt_seqnum_get(uint8_t *p_data, uint16_t len);

/**
 * @brief 备用电池序列号获取
 * 
 * @param p_data 
 * @param len 
 * @return uint16_t 
 */
uint16_t backup_batt_seqnum_get(uint8_t *p_data, uint16_t len);

/**
 * @brief 电池容量信息获取
 * 
 * @param p_data 
 * @param len 
 * @return uint16_t 
 */
uint16_t batt_capacity_info_get(uint8_t *p_data, uint16_t len);

/**
 * @brief 
 * 
 * @param p_data 
 * @param len 
 * @return uint16_t 
 */
uint16_t backup_batt_capacity_info_get(uint8_t *p_data, uint16_t len);

uint16_t batt_run_status_info_get(uint8_t *p_data, uint16_t len);

uint16_t backup_batt_run_status_info_get(uint8_t *p_data, uint16_t len);

uint16_t batt_charge_status_info_get(uint8_t *p_data, uint16_t len);

uint16_t backup_batt_charge_status_info_get(uint8_t *p_data, uint16_t len);

uint16_t batt_cell_volt_info_get(uint8_t *p_data, uint16_t len);

uint16_t backup_batt_cell_volt_info_get(uint8_t *p_data, uint16_t len);

uint16_t batt_status_info_get(uint8_t *p_data, uint16_t len);

uint16_t backup_batt_status_info_get(uint8_t *p_data, uint16_t len);

uint16_t lbatt_status_info_get(uint8_t *p_data, uint16_t len);

uint16_t exbat_stat_get(uint8_t *p_data, uint16_t len);

uint16_t econ_fault_info_get(uint8_t *p_data, uint16_t len);

uint16_t backup_batt_fault_info_get(uint8_t *p_data, uint16_t len);

uint16_t batt_fault_info_get(uint8_t *p_data, uint16_t len);

void co_key_add(uint16_t* key, uint16_t len);

void qltask_co_start(void);

void qltask_comm_start(void);

/* 判断仪表开关机(上电+can报文=开机) */
bool is_ebike_mcu_off(void);

/* 判断ebike是否在骑行 */
bool is_ebike_riding(void);

int32_t ymodem_update_result_send(char *res, uint16_t res_len);

int co_aud_cfg(aud_cfg_t *aud_cfg);

/**
 * @brief IOT控制仪表音频播放
 * 
 * @param type 播放音频类型
 * @return int 
 */
int co_aud_cmd(enum aud_type type);

/**
 * @brief IOT请求仪表复位
 * 
 * @return * int 
 */
int co_reset(void);

/**
 * @brief 小电池充电状态获取 
 * @return uint8_t 
 */
uint8_t libatt_charger_status_get(void);
/**
 * @brief IOT配置仪表音量
 * 
 * @param volume 音量大小：1-5
 * @return * int 
 */
int co_volume_cfg(int volume);

int co_pwr(void);

uint16_t co_version_get(uint8_t *p_data, uint16_t len);

uint16_t co_info_get(uint8_t *p_data, uint16_t len);

uint16_t charger_info_get(uint8_t *p_data, uint16_t len);

uint16_t elock_info_get(uint8_t *p_data, uint16_t len);

uint16_t emu_info1_get(uint8_t *p_data, uint16_t len);

uint16_t econ_stat_info2_get(uint8_t *p_data, uint16_t len);

uint16_t lbatt_chg_stat_get(uint8_t *p_data, uint16_t len);

uint16_t elock_fault_info_get(uint8_t *p_data, uint16_t len);

uint16_t charger_fault_info_get(uint8_t *p_data, uint16_t len);

/* 获取ebike助力挡位，-1代表无效，0-9和15为对应挡位 */
int8_t get_ebike_pwr_lvl(void);

/* 获取ebike当前车速 */
float get_ebike_speed(void);

/**
 * @brief 配置仪表蓝牙参数
 * 
 * @param ble_cfg 
 * @param param 0: 蓝牙感应距离，1：蓝牙无感解锁开关
 * @return * int 
 */
int co_ble_cfg(ble_cfg_t *ble_cfg, int param);

/**
 * @brief 读取仪表心跳超时时间
 * @return uint32_t 
 */
uint32_t co_mcu_timeout(void);

/**
 * @brief 获取仪表密码鉴权状态
 * 
 * @return uint8_t 0 - 未完成密码鉴权； 1 - 已完成密码鉴权
 */
uint8_t get_auth_status(void);

/**
 * @brief 获取备用电池充电状态
 * 
 * @return uint8_t 0 - 正在充电； 1 - 未充电； -1 - 无效
*/
int8_t get_backup_batt_charging_status(void);

/**
 * @brief 获取备电池是否在位
 * 
 * @return true: 在位
 *         false：不在位
 */
bool is_backup_batt_insert(void);

/**
 * @brief 获取电子锁状态
 * 
 * @return uint8_t   0 - 电子锁未打开； 1 - 电子锁打开； 0xFF - 无效状态
 */
uint8_t get_elock_status(void);

/**
 * @brief 判断充电器是否插入
 * 
 * @return uint8_t 0 - 未插入； 1 - 插入
 */
uint8_t is_charger_inserted(void);

/**
 * @brief 获取尾灯开关状态
 * 
 * @return uint8_t  0 - 关； 1 - 开
 */
uint8_t is_rear_light_on(void);

/**
 * @brief 和仪表通讯任务是否空闲
 * 
 * @return true 
 * @return false 
 */
bool is_comm_idle(void);
#endif
